package com.pattern.structure.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author yangguanzan
 * @date 3/31/22
 * @description
 */
public class SubjectInvocationHandler implements InvocationHandler {
    private BaseSubject target;
    private IAdvice advice;
    public SubjectInvocationHandler(BaseSubject target,IAdvice advice) {
        this.target = target;
        this.advice = advice;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(null!=this.target && null!=advice){
            advice.exec();
        }
        return method.invoke(this.target,args);
    }
}
